import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/dialing_function.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/personnel_management/duty_records_list/duty_records_details/duty_records_details_controller.dart';

/// 值班记录详情
class DutyRecordsDetailsPage extends StatelessWidget {
  DutyRecordsDetailsPage({super.key});

  final controller = Get.put(DutyRecordsDetailsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (controller) {
          return Scaffold(
            appBar: CustomAppBar(titleText: '值班记录详情'),
            body: Container(
                color: const Color(0xffF5F5F6),
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      AppGaps.vGap12,
                      Container(
                        height: 2.w,
                        color: const Color(0xFF587DF5),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        color: const Color(0xFFF4F7FF),
                        padding: EdgeInsets.only(left: 40.w, top: 10.w, bottom: 10.w, right: 20.w),
                        child: Text('姓名：${controller.planEntity.userName}',
                            style: TextStyle(
                              fontSize: 16.sp,
                              color: const Color(0xFF262F38),
                            )),
                      ),
                      Container(
                        height: 1.w,
                        color: const Color(0xFFDEE5FD),
                      ),
                      Container(
                        color: const Color(0xFFffffff),
                        padding: EdgeInsets.symmetric(horizontal: 40.w, vertical: 14.w),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            _getTextView(title: '类型：', value: controller.planEntity.classesName),
                            AppGaps.vGap12,
                            _getTextView(title: '状态：', value: controller.planEntity.dutyResultsName),
                            AppGaps.vGap12,
                            _getTextView(title: '人员类型：', value: controller.planEntity.personType),
                            AppGaps.vGap12,
                            _getTextView(title: '值班时间：', value: controller.planEntity.onDutyDateStr),
                            AppGaps.vGap12,
                            _getTextView(title: '上岗时间：', value: controller.planEntity.classesBeginDateRecord),
                            AppGaps.vGap12,
                            _getTextView(title: '离岗时间：', value: controller.planEntity.classesEndDateRecord),
                            AppGaps.vGap12,
                            _getTextView(title: '值班领导：', value: controller.planEntity.onDutyLeader),
                            AppGaps.vGap12,
                            Text(
                              '领导联系方式：',
                              style: TextStyle(
                                fontSize: 13.sp,
                                height: 1.2,
                                fontWeight: FontWeight.w400,
                                color: const Color(0xff7C7D93),
                              ),
                            ),
                            AppGaps.vGap10,
                            Row(
                              children: [
                                Expanded(
                                  child: Text(
                                    controller.phoneList.join(' / '),
                                    style: TextStyle(
                                      fontSize: 12.sp,
                                      height: 1.2,
                                      fontWeight: FontWeight.w400,
                                      color: const Color(0xff495061),
                                    ),
                                  ),
                                ),
                                AppGaps.hGap10,
                                SvgPicture.asset(AppImages.icon_dial, width: 32.w, height: 32.w).clickOnce(() {
                                  DialingFunction.selectDialingBottomSheet(dataList: controller.phoneList);
                                }),
                              ],
                            ),
                            AppGaps.vGap12,
                            Text(
                              controller.planEntity.dutyResults != 5 ? '值班记录：' : '原因',
                              style: TextStyle(
                                fontSize: 13.sp,
                                height: 1.2,
                                fontWeight: FontWeight.w400,
                                color: const Color(0xff7C7D93),
                              ),
                            ),
                            AppGaps.vGap10,
                            Container(
                              alignment: Alignment.topLeft,
                              padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 10.w),
                              decoration: BoxDecoration(
                                  color: const Color(0xffF7F7FB),
                                  border: Border.all(color: const Color(0xffEBEDF0), width: 1.w),
                                  borderRadius: BorderRadius.all(Radius.circular(4.r))),
                              child: Text(
                                controller.planEntity.dutyResults != 5 ? controller.planEntity.clockInRemark : controller.planEntity.askForLeave,
                                style: TextStyle(
                                  fontSize: 14.sp,
                                  height: 1.2,
                                  fontWeight: FontWeight.w400,
                                  color: const Color(0xff495061),
                                ),
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                )),
          );
        });
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, double? width}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: width ?? 110.w,
          child: Text(
            title,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff7C7D93),
            ),
          ),
        ),
        Expanded(
            child: Text(
          value,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xff495061),
          ),
        ))
      ],
    );
  }
}
